package parser
import "github.com/ChrisTrenkamp/goxpath/lexer"
const (
Empty lexer .XItemType = ""
)
type Node struct {
Val lexer .XItem
Left *Node
Right *Node
Parent *Node
next *Node
}
var beginPathType = map [lexer .XItemType ]bool {
lexer .XItemAbsLocPath : true ,
lexer .XItemAbbrAbsLocPath : true ,
lexer .XItemAbbrRelLocPath : true ,
lexer .XItemRelLocPath : true ,
lexer .XItemFunction : true ,
}
func (n *Node ) add (i lexer .XItem ) {
if n .Val .Typ == Empty {
n .Val = i
} else if n .Left == nil && n .Right == nil {
n .Left = &Node {Val : n .Val , Parent : n }
n .Val = i
} else if beginPathType [n .Val .Typ ] {
next := &Node {Val : n .Val , Left : n .Left , Right : n .Right , Parent : n }
n .Left , n .Right = next , nil
n .Val = i
} else if n .Right == nil {
n .Right = &Node {Val : i , Parent : n }
} else {
next := &Node {Val : n .Val , Left : n .Left , Right : n .Right , Parent : n }
n .Left , n .Right = next , nil
n .Val = i
}
n .next = n
}
func (n *Node ) push (i lexer .XItem ) {
if n .Left == nil {
n .Left = &Node {Val : i , Parent : n }
n .next = n .Left
} else if n .Right == nil {
n .Right = &Node {Val : i , Parent : n }
n .next = n .Right
} else {
next := &Node {Val : i , Left : n .Right , Parent : n }
n .Right = next
n .next = n .Right
}
}
func (n *Node ) pushNotEmpty (i lexer .XItem ) {
if n .Val .Typ == Empty {
n .add (i )
} else {
n .push (i )
}
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .